export class StyleMgr {
  devMode: boolean;
  constructor() {
    this.devMode = false;
  }

  static add(name: string, content: string): boolean {
    console.log(name, content);
    if (document.querySelector(`#achp-${name}`)) {
      return false;
    }
    const newStyElem = document.createElement("style");
    newStyElem.id = `achp-${name}`;
    newStyElem.innerHTML = content;
    document.head.append(newStyElem);
    return true;
  }

  static toggle(name: string, enable?: boolean) {
    const target = document.querySelector(`#achp-${name}`) as HTMLLinkElement;
    if (target) {
      if (enable != undefined) {
        target.disabled = !enable;
      } else {
        target.disabled = !target.disabled;
      }
      return true;
    }
    return false;
  }

  static remove(name: string): boolean {
    const target = document.querySelector(`#achp-${name}`) as HTMLLinkElement;
    if (target) {
      target.remove();
      return true;
    }
    return false;
  }

  static edit(name: string, newContent: string): boolean {
    const target = document.querySelector(`#achp-${name}`) as HTMLLinkElement;
    if (target) {
      target.innerHTML = newContent;
      return true;
    }
    return false;
  }
}
